<?php
/**
 * 描述
 * Created by Paco
 * Date: 2019/1/24 Time: 10:06
 */

namespace App\Http\Controllers\Admin\Product;


use App\Http\Request\Product\AttribueStore;
use App\Repositories\Product\AttribueRepository;
use Illuminate\Http\Request;

class AttrbueController
{
    private $attr;

    public function __construct(AttribueRepository $attr)
    {
        $this->attr = $attr;
    }


    public function index()
    {
        return $this->attr->getAttrNames();
    }


    public function show($attr_id)
    {
        return $this->attr->getAttrName($attr_id);
    }

    /**
     *
     * store
     * author Paco
     * createTime 2019/1/24 11:02
     * @param AttribueStore $attr
     * @param Request $request
     * @return bool
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(AttribueStore $attr, Request $request)
    {
        $params = $attr->validated($request);
        return $this->attr->addAttrName($params);
    }

    /**
     *
     * update
     * author Paco
     * createTime 2019/1/24 11:03
     * @param AttribueStore $attr
     * @param Request $request
     * @return bool
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update(AttribueStore $attr, Request $request)
    {
        $params = $attr->validated($request);
        return $this->attr->saveAttrName($params);
    }


    public function deleteAttrName(Request $request)
    {
        $attr_id = $request->input('attr_id', 0);
        return $this->attr->deleteAttribue($attr_id);
    }

    public function delAttrVal(Request $request)
    {
        $attr_value_id = $request->input('attr_value_id', 0);
        return $this->attr->deleteAttrValue($attr_value_id);
    }


}